import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

import login from '../view/login/index.vue'
import home from '../view/home/index.vue'
import artical from '../view/home/artical/'
import comment from '../view/home/comment/'
import material from '../view/home/material/'
import publish from '../view/home/publish/'
const mine = () => import('../view/home/mine/')
const textData = () => import('../view/home/textData/')
const fans = () => import('../view/home/fans/')
const fanimg = () => import('../view/home/fans/component/fanimg.vue')
const fanscul = () => import('../view/home/fans/component/fanscul.vue')
const fansfollow = () => import('../view/home/fans/component/fansfollow.vue')
const test = () => import('../view/test/msg-center.vue')
const testOne = () => import('../view/test/msg-centertest.vue')


const routes = [
    {
        path: '/login',
        component: login
    },
    {
        path: '',
        redirect: '/login'
    },
    {
        path: '/test',
        component: test
    },
    {
        path: '/testone',
        component: testOne
    },
    {
        path: '/home',
        component: home,
        children: [
            {
                path: '/artical',
                component: artical
            },
            {
                path: '/comment',
                component: comment
            },
            {
                path: '/material',
                component: material
            },
            {
                path: '/publish',
                component: publish
            },
            {
                path: '/edit/:id',
                component: publish,
                name: 'edit'
            },
            {
                path: '/mine',
                component: mine,
                name: 'mine'
            },
            {
                path: '/textData',
                component: textData,
                name: 'textData'
            },
            {
                path: '/fans',
                component: fans,
                name: 'fans',
                children: [
                    {
                        path: 'fanimg',
                        component: fanimg,
                        name: 'fanimg',
                    },
                    {
                        path: 'fanscul',
                        component: fanscul,
                        name: 'fanscul',
                    },
                    {
                        path: 'fansfollow',
                        component: fansfollow,
                        name: 'fansfollow',
                    }
                ]
            }
        ]
    }
]

const router = new VueRouter({
    routes
})

//页面加载进度条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

//全局路由守卫进入组件前
router.beforeEach((to, from, next) => {
    NProgress.start()
    next()
})
//全局路由守卫进入组件后
router.afterEach(() => {
    setTimeout(() => {
        NProgress.done()
    }, 1000);
})


//解决脚手架中连续多次点击同一个路由会报错的情况
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

export default router